
<template>
  <div class="wrap" style="padding: 15px">
    <el-row>
      <el-form :inline="true" :model="queryParams" class="demo-form-inline">
        <el-form-item label="会员卡号">
          <el-input
            clearable
            v-model="queryParams.memberCardNum"
            placeholder="会员卡号"
          ></el-input>
        </el-form-item>
        <el-form-item label="会员姓名">
          <el-input
            clearable
            v-model="queryParams.memberName"
            placeholder="会员姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input
            v-model="queryParams.phone"
            clearable
            placeholder="手机号"
          ></el-input>
        </el-form-item>
        <el-form-item label="等级">
          <el-select
            v-model="queryParams.gymLevel"
            clearable
            placeholder="等级"
          >
            <el-option
              v-for="item in levelList"
              :key="item.id"
              :label="item.levelName"
              :value="item.levelId"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <div class="block">
      <p>会员卡总余额:{{ balance.rechargeBalance }}</p>
      <p>会员红包总余额:{{ balance.preAmount }}</p>
    </div>
    <el-table :data="tableData" style="width: 100%" stripe v-loading="loading">
      <el-table-column label="会员卡号" prop="uuid"></el-table-column>
      <el-table-column label="手机号" prop="phone"></el-table-column>
      <el-table-column label="姓名" prop="memberName"></el-table-column>
      <el-table-column label="等级" prop="levelName"></el-table-column>
      <el-table-column label="余额" prop="rechargeBalance"></el-table-column>
      <el-table-column label="操作" width="500">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="show(scope.row)"
            >余额充值</el-button
          >
          <el-button
            type="primary"
            size="small"
            @click="showRedpack(scope.row.platformMemberId)"
            >查看红包</el-button
          >
          <!-- <el-button
            type="primary"
            size="small"
            @click="showCard(scope.row)"
            >查看卡信息</el-button
          > -->
          <el-button
            type="danger"
            size="small"
            @click="lock(scope.row)"
            v-if="scope.row.currentStatus == 0"
            >禁用</el-button
          >
          <el-button
            type="danger"
            size="small"
            style="background: green; border-color: green"
            @click="unlock(scope.row)"
            v-if="scope.row.currentStatus == 1"
            >解禁</el-button
          >
          <el-button type="primary" size="small" @click="userDetail(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="text-align: right; justify-content: flex-end">
      <el-pagination
        @size-change="getData"
        @current-change="getData"
        :current-page.sync="queryParams.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <Detail ref="detail" />
    <ReadPack ref="redPack" />
    <CaedList ref="cardList" />
  </div>
</template>
<script>
import Detail from './detail.vue'
import ReadPack from './redPackage.vue'
import { memberPageList, cardLevelPageList, getTotalBalance } from '@/config/api'
import { times, divide } from "@/utils/tools"
import { lockMemberList } from '@/config/interface'
import CaedList from './cardList.vue'
export default {
  components: {
    Detail,
    ReadPack,
    CaedList
  },
  data () {
    return {
      queryParams: {
        memberCardNum: undefined,
        phone: undefined,
        memberName: undefined,
        gymLevel: undefined,
        page: 1,
        pageSize: 10,
      },
      tableData: [],
      levelList: [],
      total: 0,
      loading: false,
      balance: {}
    };
  },

  created () {
    this.getData()
    this.getgLevel()
    this.getBalance()

  },
  methods: {
    lock (record) {
      this.$confirm('此操作将进行禁用, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        lockMemberList({ id: record.platformMemberId, currentStatus: 1 }).then(res => {
          this.getData()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    unlock (record) {
      this.$confirm('此操作将解除禁用, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        lockMemberList({ id: record.platformMemberId, currentStatus: 0 }).then(res => {
          this.getData()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 新增
    show (record) {
      this.$refs.detail.show(record)
    },
    showRedpack (id) {
      this.$refs.redPack.show(id)
    },
    userDetail (record) {
      this.$router.push('/sports/userInfo?id=' + record.platformMemberId)
    },
    showCard(record){
     this.$refs.cardList.show(record)
    },
    getData () {
      memberPageList(this.queryParams).then(res => {
        res.data.result.list.map(item => {
          item.rechargeBalance = divide(item.rechargeBalance, 100)
        })
        this.tableData = res.data.result.list
        this.total = res.data.result.total
      })
    },
    getgLevel () {
      cardLevelPageList().then(res => {
        this.levelList = res.data.result.list
      })
    },
    getBalance () {
      getTotalBalance().then(res => {
        res.data.result.preAmount = divide(res.data.result.preAmount || 0, 100)
        res.data.result.rechargeBalance = divide(res.data.result.rechargeBalance || 0, 100)
        this.balance = res.data.result
      })
    }
  },
};
</script>
<style lang="scss" scoped>
.block {
  display: flex;
  margin: 15px 0;
  p {
    font-size: 18px;
    font-weight: bold;
    margin-right: 50px;
  }
}
</style>